class Animal:
    def __init__(self, name):
        self.name = name

    def speak(self):
        # 父类只定义接口/默认实现，一般由子类重写
        raise NotImplementedError("子类必须实现speak方法")


# 继承Animal
class Dog(Animal):
    def speak(self):
        return f"{self.name}: 汪汪！"


class Cat(Animal):

    def speak(self):
        return f"{self.name}: 喵喵！"


dog = Dog("小黑")
cat = Cat("小花")
print(dog.speak())  # 小黑: 汪汪！
print(cat.speak())  # 小花: 喵喵！
print(isinstance(dog, Animal))  # True
print(isinstance(cat, Animal))  # cat 是否实 Animal的实例
print(isinstance(cat, object))
print(isinstance(Animal, object))

print(issubclass(Dog, Animal))  # Dog是否实Animal的派生类
print(issubclass(Cat, object))
